/*     */ package blockbuster.components.meta;
/*     */ 
/*     */ import blockbuster.components.BedrockComponentBase;
/*     */ import blockbuster.components.IComponentEmitterInitialize;
/*     */ import blockbuster.components.IComponentEmitterUpdate;
/*     */ import blockbuster.emitter.BedrockEmitter;
/*     */ import blockbuster.math.IValue;
/*     */ import blockbuster.math.molang.MolangException;
/*     */ import blockbuster.math.molang.MolangParser;
/*     */ import blockbuster.math.molang.expressions.MolangAssignment;
/*     */ import blockbuster.math.molang.expressions.MolangExpression;
/*     */ import blockbuster.math.molang.expressions.MolangMultiStatement;
/*     */ import com.google.gson.JsonElement;
/*     */ import com.google.gson.JsonObject;
/*     */ import java.util.Map;
/*     */ 
/*     */ public class BedrockComponentInitialization
/*     */   extends BedrockComponentBase
/*     */   implements IComponentEmitterInitialize, IComponentEmitterUpdate
/*     */ {
/*  21 */   public MolangExpression creation = MolangParser.ZERO;
/*  22 */   public MolangExpression update = MolangParser.ZERO;
/*     */ 
/*     */   
/*  25 */   public MolangExpression particleUpdate = MolangParser.ZERO;
/*     */ 
/*     */   
/*     */   public BedrockComponentBase fromJson(JsonElement elem, MolangParser parser) throws MolangException {
/*  29 */     if (!elem.isJsonObject()) return super.fromJson(elem, parser);
/*     */     
/*  31 */     JsonObject element = elem.getAsJsonObject();
/*     */     
/*  33 */     if (element.has("creation_expression")) this.creation = parser.parseGlobalJson(element.get("creation_expression")); 
/*  34 */     if (element.has("per_update_expression")) this.update = parser.parseGlobalJson(element.get("per_update_expression")); 
/*  35 */     if (element.has("particle_update_expression")) this.particleUpdate = parser.parseGlobalJson(element.get("particle_update_expression"));
/*     */     
/*  37 */     return super.fromJson((JsonElement)element, parser);
/*     */   }
/*     */ 
/*     */ 
/*     */   
/*     */   public JsonElement toJson() {
/*  43 */     JsonObject object = new JsonObject();
/*     */     
/*  45 */     if (!MolangExpression.isZero(this.creation)) object.add("creation_expression", this.creation.toJson()); 
/*  46 */     if (!MolangExpression.isZero(this.update)) object.add("per_update_expression", this.update.toJson()); 
/*  47 */     if (!MolangExpression.isZero(this.particleUpdate)) object.add("particle_update_expression", this.particleUpdate.toJson());
/*     */     
/*  49 */     return (JsonElement)object;
/*     */   }
/*     */ 
/*     */ 
/*     */   
/*     */   public void apply(BedrockEmitter emitter) {
/*  55 */     emitter.initialValues.clear();
/*     */     
/*  57 */     this.creation.get();
/*  58 */     cacheInitialValues(this.creation, emitter);
/*     */     
/*  60 */     if (emitter.variables != null)
/*     */     {
/*  62 */       for (Map.Entry<String, IValue> entry : (Iterable<Map.Entry<String, IValue>>)emitter.variables.entrySet())
/*     */       {
/*  64 */         emitter.initialValues.put(entry.getKey(), Double.valueOf(((IValue)entry.getValue()).get().doubleValue()));
/*     */       }
/*     */     }
/*     */   }
/*     */ 
/*     */ 
/*     */   
/*     */   public void update(BedrockEmitter emitter) {
/*  72 */     this.update.get();
/*  73 */     cacheInitialValues(this.update, emitter);
/*     */     
/*  75 */     emitter.replaceVariables();
/*     */   }
/*     */ 
/*     */   
/*     */   private void cacheInitialValues(MolangExpression e, BedrockEmitter emitter) {
/*  80 */     if (e instanceof MolangMultiStatement) {
/*     */       
/*  82 */       MolangMultiStatement statement = (MolangMultiStatement)e;
/*     */       
/*  84 */       for (MolangExpression expression : statement.expressions)
/*     */       {
/*  86 */         if (expression instanceof MolangAssignment)
/*     */         {
/*  88 */           cacheInitialValue((MolangAssignment)expression, emitter);
/*     */         }
/*     */       }
/*     */     
/*  92 */     } else if (e instanceof MolangAssignment) {
/*     */       
/*  94 */       cacheInitialValue((MolangAssignment)e, emitter);
/*     */     } 
/*     */   }
/*     */ 
/*     */   
/*     */   private void cacheInitialValue(MolangAssignment assignment, BedrockEmitter emitter) {
/* 100 */     emitter.initialValues.put(assignment.variable.getName(), Double.valueOf(assignment.variable.get().doubleValue()));
/*     */   }
/*     */ }


/* Location:              D:\fanbian\[D][龙之核心]DragonCore-2.6.0.3.jar!\blockbuster\components\meta\BedrockComponentInitialization.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */